<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h3 {
            height: 400px;
        }
    </style>
</head>

<body>
    <h3>哈哈</h3>
    <h3>哈哈</h3>
    <h3>哈哈</h3>
    <h3>哈哈</h3>
    <h3>哈哈</h3>
    <h3>哈哈</h3>
    <script>

        function debounce(fn,delay){
            var timer=null;
            return function(){
                if(timer){
                    clearTimeout(timer)
                }
                timer=setTimeout(fn,delay)
            }
        }

        //滚动事件
        window.onscroll = debounce(scrollHandle,200)    
        function scrollHandle() {
            var scrollTop=document.documentElement.scrollTop;
            console.log(scrollTop);
        }

    </script>
</body>

</html>